package util;

import java.math.BigDecimal;

public class Calculate {
    //求一个数组的最小值
    public static int getMin(int[] a){
        int min = a[0];
        int a_length = a.length;
        for (int i = 1; i < a_length; i++ )
        {
            if (a[i] < min)
            {
                min = a[i];
            }
        }
        return min;
    }

    //保留scale个小数位
    public static double chooseScale(double a,int scale){
        BigDecimal db = new BigDecimal(a);
        return db.setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue(); // 保留scale位小数并四舍五入
    }

    //计算一个数组中的各个样本的探针数量
    public static void countNumber(String[] sample,int[] countsPerSeg){
        String[] unique_sample = Process.unique(sample);
        int seg_number = sample.length;
        int sample_length = unique_sample.length;
        int[] num = new int[sample_length];
        int k = 0;

        for (int j = 0; j < seg_number; j++) {
            if(sample[j].equals(unique_sample[k])){
                num[k]+= countsPerSeg[j];
            }else {
                k++;
                num[k]+= countsPerSeg[j];
            }
        }
        for (int i = 0; i < sample_length; i++){
            System.out.println( unique_sample[i] + "样本有探针数量：" + num[i]);
        }
    }

}
